//
//  BuyRedFlower.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/24.
//

#import "BuyRedFlower.h"
#import "CommonUtil.h"

@interface BuyRedFlower()

@property (strong, nonatomic) UILabel * titleLabel;
@property (strong, nonatomic) UITextField * numberField;
@property (strong, nonatomic) UILabel * duoLabel;
@property (strong, nonatomic) UILabel * tipLabel1;
@property (strong, nonatomic) UILabel * tipLabel2;
@property (strong, nonatomic) UILabel * tipLabel3;

@property (strong, nonatomic) UIButton * cancelBtn;
@property (strong, nonatomic) UIButton * confirmBtn;

@end

@implementation BuyRedFlower


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.whiteView];
        self.whiteView.layer.cornerRadius = AD(20);
       
    }
    return self;
}


-(void)show{
 
    [super show];
    
    self.whiteView.frame = CGRectMake(AD(50), 0, SCREEN_WIDTH-AD(100), AD(240));
    self.whiteView.centerY = SCREEN_HEIGHT/2;
    [self.whiteView addSubview:self.titleLabel];
    [self.whiteView addSubview:self.numberField];
    [self.whiteView addSubview:self.duoLabel];
    [self.whiteView addSubview:self.tipLabel1];
    [self.whiteView addSubview:self.tipLabel2];
    [self.whiteView addSubview:self.tipLabel3];
    [self.whiteView addSubview:self.cancelBtn];
    [self.whiteView addSubview:self.confirmBtn];
    
    
    [self setAttributeWithLabel:self.tipLabel1 redText:@"0.01"];
    [self setAttributeWithLabel:self.tipLabel2 redText:@"0.00"];
    [self setAttributeWithLabel:self.tipLabel3 redText:@"2.61"];
    
    
    
}
    
    
    - (void)cancelBtnClick:(UIButton *)sender{
        [self dismiss];
    }
    
    - (void)confirmBtnClick:(UIButton *)sender{
        
        if (self.actionBlock) {
            self.actionBlock(@"123");
        }
        [self dismiss];
    }
    
    
- (void)setAttributeWithLabel:(UILabel *)label redText:(NSString *)redText{
    NSMutableAttributedString *attribut = [[NSMutableAttributedString alloc]initWithString:label.text];
    NSRange range1 = [label.text rangeOfString:redText];
    [attribut addAttribute:NSForegroundColorAttributeName value:RGB(255.0, 90.0, 117.0) range:range1];
    label.attributedText = attribut;
}

    
#pragma mark - lazy

-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.whiteView.width, AD(50))];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont systemFontOfSize:AD(18)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.text = @"购买小红花";
    }
    return _titleLabel;
}

-(UITextField *)numberField{
    if (!_numberField) {
        _numberField = [[UITextField alloc] initWithFrame:CGRectMake(AD(30), _titleLabel.bottom + AD(10), AD(200), AD(40))];
        _numberField.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3];
        _numberField.layer.cornerRadius = AD(5);
        _numberField.keyboardType = UIKeyboardTypeNumberPad;
        _numberField.placeholder = @"  请输入购买数量";
    }
    return _numberField;
}

-(UILabel *)duoLabel{
    if (!_duoLabel) {
        _duoLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.numberField.right+ AD(5), _numberField.top, AD(30), _numberField.height)];
        _duoLabel.textColor = [UIColor blackColor];
        _duoLabel.font = [UIFont systemFontOfSize:AD(18)];
        _duoLabel.text = @"朵";
    }
    return _duoLabel;
}
-(UILabel *)tipLabel1{
    if (!_tipLabel1) {
        _tipLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(0, _numberField.bottom +AD(10), self.whiteView.width, AD(30))];
        _tipLabel1.textColor = [UIColor blackColor];
        _tipLabel1.font = [UIFont systemFontOfSize:AD(18)];
        _tipLabel1.text = @"每朵小红花单价0.01元";
        _tipLabel1.textAlignment = NSTextAlignmentCenter;
    }
    return _tipLabel1;
}

-(UILabel *)tipLabel2{
    if (!_tipLabel2) {
        _tipLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(-AD(20), _tipLabel1.bottom +AD(10), self.whiteView.width/2, AD(30))];
        _tipLabel2.textColor = [UIColor blackColor];
        _tipLabel2.font = [UIFont systemFontOfSize:AD(16)];
        _tipLabel2.text = @"合计0.00元";
        _tipLabel2.textAlignment = NSTextAlignmentRight;
    }
    return _tipLabel2;
}

-(UILabel *)tipLabel3{
    if (!_tipLabel3) {
        _tipLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(_tipLabel2.right, _tipLabel2.top, self.whiteView.width/2, AD(30))];
        _tipLabel3.textColor = [UIColor blackColor];
        _tipLabel3.font = [UIFont systemFontOfSize:AD(16)];
        _tipLabel3.text = @"(可用金额2.61元)";
        _tipLabel3.textAlignment = NSTextAlignmentLeft;
    }
    return _tipLabel3;
}

    -(UIButton *)cancelBtn{
        if (!_cancelBtn) {
            _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [_cancelBtn addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
            [_cancelBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:AD(18)];
            _cancelBtn.layer.borderWidth = AD(1);
            _cancelBtn.layer.cornerRadius = AD(5);
            CGFloat w = (self.whiteView.width - AD(30) - AD(15) - AD(30))/2;
            _cancelBtn.frame = CGRectMake(AD(30), _tipLabel3.bottom + AD(10), w, AD(35));
        }
        
        return _cancelBtn;
    }
    
    -(UIButton *)confirmBtn{
        if (!_confirmBtn) {
            _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [_confirmBtn addTarget:self action:@selector(confirmBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [_confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
            [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:AD(18)];
            _confirmBtn.layer.cornerRadius = AD(5);
            _confirmBtn.backgroundColor = RGB(255.0, 90.0, 117.0);
            CGFloat w = (self.whiteView.width - AD(30) - AD(15) - AD(30))/2;
            _confirmBtn.frame = CGRectMake(_cancelBtn.right + AD(15), _tipLabel3.bottom + AD(10), w, AD(35));
        }
        
        return _confirmBtn;
    }

@end
